package com.gxa.logistics.controller;

import com.gxa.logistics.common.base.RespResult;
import com.gxa.logistics.domain.dto.EmployeeSaveDTO;
import com.gxa.logistics.domain.dto.EmployeeUpdateDTO;
import com.gxa.logistics.domain.dto.MenuSaveDTO;
import com.gxa.logistics.domain.dto.MenuUpdateDTO;
import com.gxa.logistics.domain.entity.Menu;
import com.gxa.logistics.service.MenuService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "系统管理-菜单管理")
@RestController
@RequestMapping("/menu")
@Slf4j
public class MenuController {

    @Autowired
    private MenuService menuService;

    /**
     * 获取菜单列表
     */
    @ApiOperation(value = "获取菜单列表", notes = "获取菜单列表")
    @GetMapping("/list")
    public RespResult<List<Menu>> list(){
        return menuService.list();
    }

    @ApiOperation(value = "新增菜单", notes = "新增菜单")
    @PostMapping("/save")
    public RespResult save(@RequestBody @ApiParam(name = "data",value = "新增菜单") @Validated MenuSaveDTO menuSaveDTO) {
        // 保存
        menuService.insertMenu(menuSaveDTO);
        return RespResult.success();
    }

    @ApiOperation(value = "修改菜单", notes = "修改菜单")
    @PostMapping("/update")
    public RespResult update(@RequestBody @ApiParam(name = "data",value = "修改菜单") MenuUpdateDTO menuUpdateDTO) {
        menuService.updateMenu(menuUpdateDTO);
        return RespResult.success();
    }

    @ApiOperation(value = "删除菜单", notes = "删除菜单")
    @ApiImplicitParam(name = "menu_id",value = "菜单id",required = true,dataType = "String",paramType = "path")
    @PostMapping("/delete/{menu_id}")
    public RespResult delete(@PathVariable("menu_id") Integer menuId){
        menuService.deleteMenuById(menuId);
        return RespResult.success();
    }
}
